package com.common.baselib.runtimepermission;


import androidx.fragment.app.FragmentActivity;

/**
 * @author 李丹丹<br>
 * 2018/8/29
 */
public class NicePermission {

    private FragmentActivity activity;
    private NicePermissionListener permissionListener = null;

    public NicePermission(FragmentActivity activity, NicePermissionListener permissionListener) {
        this.activity = activity;
        this.permissionListener = permissionListener;
    }

    public void requestPermission(final String... permissons) {
        requestSet(permissons);

    }

    private void requestSet(String[] permissons) {

        RxPermissions rxPermissions = new RxPermissions(activity);
        rxPermissions.request(permissons).subscribe(granted -> {
            if (granted) {
                // All requested permissions are granted
                if (permissionListener != null) {
                    permissionListener.onGranted();
                }
            } else {
                // At least one permission is denied
                if (permissionListener != null) {
                    permissionListener.onRefused();
                }
            }
        });

    }
}
